package com.notion.algorithms.datastructures;

public class Element implements Comparable<Element> {
	private final int weight;
	private final int length;

	public Element(int weight,int length){
		this.weight = weight;
		this.length = length;
	}


	public int getWeight() {
		return weight;
	}


	public int getLength() {
		return length;
	}


	public int compareTo(Element arg0) {
		int comparedValue = (this.getWeight()-this.length)-(arg0.getWeight()-arg0.getLength());
		if(comparedValue==0){
			if(this.getWeight()>arg0.getWeight())
				comparedValue=1;
			else if(this.getWeight()<arg0.getWeight())
				comparedValue=-1;			
		}
		return comparedValue;
	}
	
	@Override
	public boolean equals(Object obj) {
		boolean equalsResult = false;
		Element paramElement;
		if((obj instanceof Element)){
			paramElement = (Element)obj;
			equalsResult = (this.getLength()==paramElement.getLength()
					&& this.getWeight()==paramElement.getWeight());
		}
		return equalsResult;
		
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "Weight="+this.getWeight()+";Length="+this.getLength();
	}

}
